/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package clientereligadora.paineis;

import clientereligadora.formularios.FormGrafico;
import clientereligadora.formularios.FormPrincipal;
import java.awt.BorderLayout;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.data.jdbc.JDBCPieDataset;
import org.jfree.util.Rotation;

 

/**
 *
 * @author leandro.aquino
 */
public final class PainelChart extends javax.swing.JPanel {

   

    /**
     * Creates new form PainelChart
     */
    public PainelChart() throws SQLException   {
       
        initComponents();
        
      chamaPie();

    }
   public void chamaPie() throws SQLException{
     try {       
            pieChart();
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(FormGrafico.class.getName()).log(Level.SEVERE, null, ex);
        } 
}

    public void pieChart() throws SQLException, ClassNotFoundException {
        String query = "select evento.id_religadora AS RELIGADORA, evento.tipo_evento AS EVENTO from dataserverreligadora.evento "
                + "WHERE `data` > 2013-01-04 "
                + "ORDER BY id_religadora";

        JDBCPieDataset dataset1 = new JDBCPieDataset("jdbc:mysql://localhost:3306/dataserverreligadora", "com.mysql.jdbc.Driver",
                "root", "ntk1120");

        dataset1.executeQuery(query);
      
        JFreeChart chart = ChartFactory.createPieChart(" Religadora", dataset1, true, true, true);

        // JFreeChart chart = ChartFactory.createPieChart(query, dataset1, rootPaneCheckingEnabled, rootPaneCheckingEnabled, Locale.)
        ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(650, 270));

        JFreeChart chart1 = ChartFactory.createPieChart3D(" Religadora", dataset1, true, true, true);

        final PiePlot3D plot = (PiePlot3D) chart1.getPlot();
        plot.setStartAngle(290);
        plot.setDirection(Rotation.CLOCKWISE);
        plot.setForegroundAlpha(0.5f);
        plot.setNoDataMessage("No data to display");
        plot.setIgnoreZeroValues(true);
        plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} {2} "));

        ChartPanel chartPanel1 = new ChartPanel(chart1);
        chartPanel1.setDomainZoomable(true);
        // pchart.jScrollPane1.add(new ChartPanel(chart1));
        jPanel2.add(chartPanel1, BorderLayout.CENTER);
        jPanel2.validate();  
        jPanel2.show();

       }
   

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();

        setBackground(new java.awt.Color(255, 255, 255));
        setPreferredSize(new java.awt.Dimension(742, 489));

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jPanel2.setPreferredSize(new java.awt.Dimension(720, 459));
        jPanel2.setLayout(new java.awt.BorderLayout());

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap(12, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap(19, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    public static javax.swing.JPanel jPanel2;
    // End of variables declaration//GEN-END:variables
}
